package com.sm.imlibrary.model;

import android.text.Editable;
import android.text.TextUtils;
import android.widget.FrameLayout;

import com.sm.imlibrary.roondao.RoomDaoApi;
import com.sm.imlibrary.roondao.entity.DbChatText;
import com.sm.imlibrary.imsdk.SIMMessage;

/**
 * created by zhud on 2019/7/9
 */
public class TextMessage extends Message {

    private String content;

    public TextMessage(SIMMessage message) {
        this.message = message;
    }

    public TextMessage(Editable editable) {
        message = new SIMMessage();
        message.getChatMessage().messageType = SIMElemType.Text.name();
        content = editable.toString();
    }

    @Override
    public void showMessage(FrameLayout frameLayout) {

    }

    public String getContent() {
        if (TextUtils.isEmpty(content)) {
            Long textId = message.getChatMessage().messageTextId;
            DbChatText chatText = RoomDaoApi.getInstance().getDatabase().chatTextDao().selectById(textId);
            if (chatText != null)
                content = chatText.content;
        }
        return content;
    }
}
